import java.util.ArrayList;

class LevelController
{
	private ArrayList<Level> levels;
	private int index;
	
	public LevelController()
	{
		levels = new ArrayList<Level>();
		index = 0;
	}
	
	public void addLevel(Level l)
	{
		l.setController(this);
		levels.add(l);
	}
	
	public void removeLevel(Level l)
	{
		l.removeController();
		levels.remove(l);
	}
	
	public void nextLevel()
	{
		if(index == levels.size()-1)
			return;
		
		index++;
	}
	
	public void previousLevel()
	{
		if(index == 0)
			return;
		
		index--;
	}
	
	public boolean jumpToLevel(Level l)
	{
		for(int x = 0; x < levels.size(); x++)
			if(levels.get(x) == l)
			{
				index = x;
				return true;
			}
		
		return false;
	}
	
	public boolean jumpToLevel(int l)
	{
		if(l < 0 || l >= levels.size())
			return false;
		
		index = l;
		return true;
	}
}